
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Castle.ActiveRecord;

/// <summary>
/// Summary description for Contents
/// </summary>
/// 

    [ActiveRecord]
    public class Contents : ActiveRecordBase<Contents>
    {
        public static NHibernate.Expression.MatchMode Exact = NHibernate.Expression.MatchMode.Exact;
        public static NHibernate.Expression.MatchMode Anywhere = NHibernate.Expression.MatchMode.Anywhere;
        public static NHibernate.Expression.MatchMode End = NHibernate.Expression.MatchMode.End;
        public static NHibernate.Expression.MatchMode Start = NHibernate.Expression.MatchMode.Start;


        private int contentID;

        [PrimaryKey(PrimaryKeyType.Identity)]
        public int ContentID
        {
            get { return contentID; }
            set { contentID = value; }
        }
        private String contentText;

        [Property(ColumnType = "StringClob")]
        public String ContentText
        {
            get { return contentText; }
            set { contentText = value; }
        }

        private String description;

        [Property]
        public String Description
        {
            get { return description; }
            set { description = value; }
        }

        private bool activeFlag;
        [Property]
        public bool ActiveFlag
        {
            get { return activeFlag; }
            set { activeFlag = value; }
        }

        private DateTime createdDate;
        [Property]
        public DateTime CreatedDate
        {
            get { return createdDate; }
            set { createdDate = value; }
        }

        private DateTime updatedDate;
        [Property]
        public DateTime UpdatedDate
        {
            get { return updatedDate; }
            set { updatedDate = value; }
        }

        private String createdBy;
        [Property]
        public String CreatedBy
        {
            get { return createdBy; }
            set { createdBy = value; }
        }


        private String updatedBy;

        [Property]
        public String UpdatedBy
        {
            get { return updatedBy; }
            set { updatedBy = value; }
        }

        private String pageName;
        [Property]
        public String PageName
        {
            get { return pageName; }
            set { pageName = value; }
        }

        public Contents()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Contents(String ContentText, String Description, bool activeFlag, String createdBy, String PageName)
        {
            this.contentText = ContentText;
            this.description = Description;
            this.createdBy = createdBy;
            this.updatedBy = createdBy;
            this.createdDate = DateTime.Now;
            this.updatedDate = DateTime.Now;
            this.activeFlag = activeFlag;
            this.pageName = PageName;
        }

        public static void delete_Content(int Contentid)
        {
            Contents Content = get_Content(Contentid);
            Content.Delete();
        }


        public static void update_Content(int ContentID, String ContentText, String Description, bool activeFlag, String updatedBy, String PageName)
        {
            Contents Content = new Contents();
            Content = get_Content(ContentID);
            Content.contentText = ContentText;
            Content.description = Description;
            Content.activeFlag = activeFlag;
            Content.UpdatedBy = updatedBy;
            Content.updatedDate = DateTime.Now;
            Content.pageName = PageName;
            Content.Update();
        }

        public static void update_Content(int ContentID, bool activeFlag, String updatedBy)
        {
            Contents Content = new Contents();
            Content = get_Content(ContentID);
            Content.activeFlag = activeFlag;
            Content.UpdatedBy = updatedBy;
            Content.updatedDate = DateTime.Now;
            Content.Update();
        }

        public static void create_Content(String ContentText, String Description, bool activeFlag, String createdBy, String PageName)
        {
            Contents Content = new Contents(ContentText, Description, activeFlag, createdBy, PageName);
            Content.Create();

        }

        public static Contents get_Content(int Contentid)
        {
            return FindByPrimaryKey(Contentid);
        }

        public static Contents get_Content(string PageName)
        {
            Contents[] body = FindAllByProperty("PageName", PageName);
            if (body != null && body.Length > 0)
                return body[0];
            return null;
        }

        public static Contents[] get_all_Content()
        {
            return FindAll();
        }

        public static int count_all_Content()
        {
            return Count();
        }

        public static Contents[] search_Content(String propertyName, String textSearch, NHibernate.Expression.MatchMode mode)
        {
            NHibernate.Expression.DetachedCriteria criteria = NHibernate.Expression.DetachedCriteria.For<Contents>();

            criteria.Add(NHibernate.Expression.Expression.InsensitiveLike(propertyName, textSearch, mode));

            return FindAll(criteria, Contents.Asc(propertyName));
        }

        public static Contents[] get_Content_and_sort(String propertyName, String order)
        {
            NHibernate.Expression.DetachedCriteria avgWeight = NHibernate.Expression.DetachedCriteria.For<Contents>();
            if (order == "ASC")
                return FindAll(avgWeight, Asc(propertyName));
            return FindAll(avgWeight, Desc(propertyName));
        }
    }